package com.stek.utils;

import android.content.Context;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.stek.R;

public class GATracking {
	// ======================================================
	private static GATracking INSTANCE;
	private Tracker mTracker;

	// ======================================================
	public GATracking(Context context) {
		super();
		if (mTracker == null) {
			GoogleAnalytics analytics = GoogleAnalytics.getInstance(context);
			mTracker = analytics.newTracker(context
					.getString(R.string.ga_tracking_id));
		}
	}

	public static synchronized GATracking getInstance(Context context) {
		if (null == INSTANCE) {
			INSTANCE = new GATracking(context);
		}
		return INSTANCE;
	}

	// ======================================================
	public void sendScreenView(Class<?> clazz) {
		mTracker.setScreenName(clazz.getName());
		mTracker.send(new HitBuilders.AppViewBuilder().build());
	}

	public void sendEvent(String category, String action, String label) {
		mTracker.send(new HitBuilders.EventBuilder().setCategory(category)
				.setAction(action).setLabel(label).build());
	}

	public void sendException(String description, boolean isFata) {
		mTracker.send(new HitBuilders.ExceptionBuilder()
				.setDescription(description).setFatal(isFata).build());
	}
}
